{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sqlalchemy import create_engine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "base_path =r\"D:\\study\\yxl\\exercises\\ljt_data_deal\\meixi\\static\\JSON\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "json01 = pd.read_json(base_path+\"/goods_scroll.json\",encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>img</th>\n",
       "      <th>name1</th>\n",
       "      <th>name2</th>\n",
       "      <th>state</th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>img/scroll_1.jpg</td>\n",
       "      <td>TOMBOLINI</td>\n",
       "      <td>东博利尼</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>东博利尼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>img/scroll_2.jpg</td>\n",
       "      <td>Burberry</td>\n",
       "      <td>博柏利</td>\n",
       "      <td>已加入收藏</td>\n",
       "      <td>博柏利</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>img/scroll_3.jpg</td>\n",
       "      <td>McQ by Alexander McQueen</td>\n",
       "      <td>麦蔻</td>\n",
       "      <td>已被购买</td>\n",
       "      <td>麦蔻</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>img/scroll_4.jpg</td>\n",
       "      <td>Prada</td>\n",
       "      <td>普拉达</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>普拉达</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>img/scroll_5.jpg</td>\n",
       "      <td>Balmain</td>\n",
       "      <td>巴尔曼</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>巴尔曼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>img/scroll_6.jpg</td>\n",
       "      <td>Bottega Veneta</td>\n",
       "      <td>葆蝶家</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>葆蝶家 衣服</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>img/scroll_7.jpg</td>\n",
       "      <td>Prada</td>\n",
       "      <td>普拉达</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>普拉达 衣服</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>img/scroll_8.jpg</td>\n",
       "      <td>Coach</td>\n",
       "      <td>蔻驰</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>蔻驰 衣服</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "      <td>img/scroll_9.jpg</td>\n",
       "      <td>Burberry</td>\n",
       "      <td>博柏利</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>博柏利 好衣服</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "      <td>img/scroll_10.jpg</td>\n",
       "      <td>VERSACE JEANS</td>\n",
       "      <td>范思哲牛仔</td>\n",
       "      <td>已加入购物袋</td>\n",
       "      <td>范思哲牛仔 好衣服</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id                img                      name1  name2   state      title\n",
       "0   1   img/scroll_1.jpg                  TOMBOLINI   东博利尼  已加入购物袋       东博利尼\n",
       "1   2   img/scroll_2.jpg                  Burberry     博柏利   已加入收藏        博柏利\n",
       "2   3   img/scroll_3.jpg  McQ by Alexander McQueen      麦蔻    已被购买         麦蔻\n",
       "3   4   img/scroll_4.jpg                      Prada    普拉达  已加入购物袋        普拉达\n",
       "4   5   img/scroll_5.jpg                   Balmain     巴尔曼  已加入购物袋        巴尔曼\n",
       "5   6   img/scroll_6.jpg            Bottega Veneta     葆蝶家  已加入购物袋     葆蝶家 衣服\n",
       "6   7   img/scroll_7.jpg                      Prada    普拉达  已加入购物袋     普拉达 衣服\n",
       "7   8   img/scroll_8.jpg                      Coach     蔻驰  已加入购物袋      蔻驰 衣服\n",
       "8   9   img/scroll_9.jpg                   Burberry    博柏利  已加入购物袋    博柏利 好衣服\n",
       "9  10  img/scroll_10.jpg              VERSACE JEANS  范思哲牛仔  已加入购物袋  范思哲牛仔 好衣服"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sqlalchemy import create_engine\n",
    "import pymysql\n",
    "from pymysql import IntegrityError \n",
    "import uuid\n",
    "from sqlalchemy import create_engine "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "engine = create_engine('mysql://root:root@127.0.0.1/meixi?charset=utf8')#用sqlalchemy创建引擎 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "json01.to_sql(name='goods', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_info = pd.read_json(base_path+\"/goods_info.json\",encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_info = pd.read_json(base_path+\"/goods_info.json\",encoding='utf-8')\n",
    "goods_list = pd.read_json(base_path+\"/goods_list.json\",encoding='utf-8')\n",
    "goods_list1 = pd.read_json(base_path+\"/goods_list1.json\",encoding='utf-8')\n",
    "goods_scroll = pd.read_json(base_path+\"/goods_scroll.json\",encoding='utf-8')\n",
    "list_edit = pd.read_json(base_path+\"/list_edit.json\",encoding='utf-8')\n",
    "list_edit2 = pd.read_json(base_path+\"/list_edit2.json\",encoding='utf-8')\n",
    "slide = pd.read_json(base_path+\"/slide.json\",encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_info.to_sql(name='goods_info', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_list.to_sql(name='goods_list', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_list1.to_sql(name='goods_list1', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "goods_scroll.to_sql(name='goods_scroll', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_edit.to_sql(name='list_edit', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_edit2.to_sql(name='list_edit2', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "slide.to_sql(name='slide', con=engine, chunksize=1000, if_exists='replace', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>des</th>\n",
       "      <th>ori</th>\n",
       "      <th>dis</th>\n",
       "      <th>time</th>\n",
       "      <th>buy</th>\n",
       "      <th>bags</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>Dolce Gabbana 杜嘉班纳</td>\n",
       "      <td>SICILY 小牛皮 女士 两用包</td>\n",
       "      <td>参考价：￥10850.00</td>\n",
       "      <td>8680</td>\n",
       "      <td>到货时间：该商品到货时间预计3-5个工作日</td>\n",
       "      <td>/static/img/buy.gif</td>\n",
       "      <td>/static/img/buy.gif</td>\n",
       "      <td>/static/img/bag1.jpg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>Fendi 芬迪</td>\n",
       "      <td>牛皮 女士 斜挎包</td>\n",
       "      <td>参考价：￥6600.00</td>\n",
       "      <td>5280</td>\n",
       "      <td>到货时间：该商品到货时间预计3-5个工作日</td>\n",
       "      <td>/static/img/buy.gif</td>\n",
       "      <td>/static/img/bags.gif</td>\n",
       "      <td>/static/img/bag01.jpg</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id                name                des            ori   dis  \\\n",
       "0   1  Dolce Gabbana 杜嘉班纳  SICILY 小牛皮 女士 两用包  参考价：￥10850.00  8680   \n",
       "1   2           Fendi 芬迪           牛皮 女士 斜挎包   参考价：￥6600.00  5280   \n",
       "\n",
       "                    time                  buy                  bags  \\\n",
       "0  到货时间：该商品到货时间预计3-5个工作日  /static/img/buy.gif   /static/img/buy.gif   \n",
       "1  到货时间：该商品到货时间预计3-5个工作日  /static/img/buy.gif  /static/img/bags.gif   \n",
       "\n",
       "                     img  \n",
       "0   /static/img/bag1.jpg  \n",
       "1  /static/img/bag01.jpg  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "goods_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:root] *",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
